package constructor;
//Object

import java.util.Objects;

public class Car {
   public  String name;
   public  double price;
   private int id;

    public int getId() {
        return 455+id;
    }

    public void setId(int id) {
        id  = id +1 ;
        this.id = id;

    }

    /**
     无参数构造器
     */
    public Car(){
        System.out.println("==无参数构造器被调用了=");
    }

    /**
     有参数构造器
     */
    public Car(String n, double p){
        System.out.println("==有参数构造器被调用了=");
        name = n;
        price = p;
        test(1);
    }

    @Override //重写
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price=" + price +
                ", id=" + id +
                '}';
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Car car = (Car) o;
        return Double.compare(car.price, price) == 0 && id == car.id && Objects.equals(name, car.name);
    }

    @Override //重写
    public int hashCode() {
        super.hashCode();
        String a = "S";
        return Objects.hash(name, price, id);
    }

    //方法的重载
    public  void test(){


    }
    public  void test(int a){


    }
}
